package org.github.manx98.jlibhac.common.keys;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Manx98
 * @version 1.0
 * @since 2022/10/3 0:04
 */
public class DefaultKeySet {
    public static List<KeyInfo> createKeyList() {
        List<KeyInfo> keys = new ArrayList<>(70);
        // Keys with a group value of -1 are keys that will be read but not written.
        // This is for compatibility since some keys had other names in the past.

        // TSEC secrets aren't public yet, so the TSEC root keys will be treated as
        // root keys even though they're derived.

        keys.add(new KeyInfo(10, KeyType.DeviceRoot, "secure_boot_key", (set, i) -> set.SecureBootKey));
        keys.add(new KeyInfo(11, KeyType.DeviceRoot, "tsec_key", (set, i) -> set.TsecKey));
        keys.add(new KeyInfo(12, KeyType.DeviceDrvd, "device_key", (set, i) -> set.DeviceKey));
        keys.add(new KeyInfo(20, KeyType.CommonRoot, "tsec_root_kek", (set, i) -> set.TsecRootKek));
        keys.add(new KeyInfo(21, KeyType.CommonRoot, "package1_mac_kek", (set, i) -> set.Package1MacKek));
        keys.add(new KeyInfo(22, KeyType.CommonRoot, "package1_kek", (set, i) -> set.Package1Kek));
        keys.add(new KeyInfo(30, KeyType.CommonRoot, "tsec_auth_signature", 0, 0x20, (set, i) -> set.TsecAuthSignatures[i]));
        keys.add(new KeyInfo(40, KeyType.CommonRoot, "tsec_root_key", 0, 0x20, (set, i) -> set.TsecRootKeys[i]));
        keys.add(new KeyInfo(50, KeyType.CommonSeed, "keyblob_mac_key_source", (set, i) -> set.KeyBlobMacKeySource));
        keys.add(new KeyInfo(51, KeyType.CommonSeed, "keyblob_key_source", 0, 6, (set, i) -> set.KeyBlobKeySources[i]));
        keys.add(new KeyInfo(55, KeyType.DeviceDrvd, "keyblob_key", 0, 6, (set, i) -> set.KeyBlobKeys[i]));
        keys.add(new KeyInfo(60, KeyType.DeviceDrvd, "keyblob_mac_key", 0, 6, (set, i) -> set.KeyBlobMacKeys[i]));
        keys.add(new KeyInfo(70, KeyType.DeviceRoot, "encrypted_keyblob", 0, 6, (set, i) -> set.EncryptedKeyBlobs[i]));
        keys.add(new KeyInfo(80, KeyType.CommonRoot, "keyblob", 0, 6, (set, i) -> set.KeyBlobs[i]));
        keys.add(new KeyInfo(90, KeyType.CommonSeed, "master_kek_source", 6, 0x20, (set, i) -> set.MasterKekSources[i]));
        keys.add(new KeyInfo(100, KeyType.CommonRoot, "mariko_bek", (set, i) -> set.MarikoBek));
        keys.add(new KeyInfo(101, KeyType.CommonRoot, "mariko_kek", (set, i) -> set.MarikoKek));
        keys.add(new KeyInfo(110, KeyType.CommonRoot, "mariko_aes_class_key", 0, 0xC, (set, i) -> set.MarikoAesClassKeys[i]));
        keys.add(new KeyInfo(120, KeyType.CommonSeedDiff, "mariko_master_kek_source", 0, 0x20, (set, i) -> set.MarikoMasterKekSources[i]));
        keys.add(new KeyInfo(130, KeyType.CommonDrvd, "master_kek", 0, 0x20, (set, i) -> set.MasterKeks[i]));
        keys.add(new KeyInfo(140, KeyType.CommonSeed, "master_key_source", (set, i) -> set.MasterKeySource));
        keys.add(new KeyInfo(150, KeyType.CommonDrvd, "master_key", 0, 0x20, (set, i) -> set.MasterKeys[i]));
        keys.add(new KeyInfo(160, KeyType.CommonDrvd, "package1_key", 0, 0x20, (set, i) -> set.Package1Keys[i]));
        keys.add(new KeyInfo(170, KeyType.CommonDrvd, "package1_mac_key", 6, 0x20, (set, i) -> set.Package1MacKeys[i]));
        keys.add(new KeyInfo(180, KeyType.CommonSeed, "package2_key_source", (set, i) -> set.Package2KeySource));
        keys.add(new KeyInfo(190, KeyType.CommonDrvd, "package2_key", 0, 0x20, (set, i) -> set.Package2Keys[i]));
        keys.add(new KeyInfo(200, KeyType.CommonSeed, "bis_kek_source", (set, i) -> set.BisKekSource));
        keys.add(new KeyInfo(201, KeyType.CommonSeed, "bis_key_source", 0, 4, (set, i) -> set.BisKeySources[i]));
        keys.add(new KeyInfo(205, KeyType.DeviceDrvd, "bis_key", 0, 4, (set, i) -> set.BisKeys[i]));
        keys.add(new KeyInfo(210, KeyType.CommonSeed, "per_console_key_source", (set, i) -> set.PerConsoleKeySource));
        keys.add(new KeyInfo(211, KeyType.CommonSeed, "retail_specific_aes_key_source", (set, i) -> set.RetailSpecificAesKeySource));
        keys.add(new KeyInfo(212, KeyType.CommonSeed, "aes_kek_generation_source", (set, i) -> set.AesKekGenerationSource));
        keys.add(new KeyInfo(213, KeyType.CommonSeed, "aes_key_generation_source", (set, i) -> set.AesKeyGenerationSource));
        keys.add(new KeyInfo(214, KeyType.CommonSeed, "titlekek_source", (set, i) -> set.TitleKekSource));
        keys.add(new KeyInfo(220, KeyType.CommonDrvd, "titlekek", 0, 0x20, (set, i) -> set.TitleKeks[i]));
        keys.add(new KeyInfo(230, KeyType.CommonSeed, "header_kek_source", (set, i) -> set.HeaderKekSource));
        keys.add(new KeyInfo(231, KeyType.CommonSeed, "header_key_source", (set, i) -> set.HeaderKeySource));
        keys.add(new KeyInfo(232, KeyType.CommonDrvd, "header_key", (set, i) -> set.HeaderKey));
        keys.add(new KeyInfo(240, KeyType.CommonSeed, "key_area_key_application_source", (set, i) -> set.KeyAreaKeyApplicationSource));
        keys.add(new KeyInfo(241, KeyType.CommonSeed, "key_area_key_ocean_source", (set, i) -> set.KeyAreaKeyOceanSource));
        keys.add(new KeyInfo(242, KeyType.CommonSeed, "key_area_key_system_source", (set, i) -> set.KeyAreaKeySystemSource));
        keys.add(new KeyInfo(250, KeyType.CommonSeed, "save_mac_kek_source", (set, i) -> set.DeviceUniqueSaveMacKekSource));
        keys.add(new KeyInfo(251, KeyType.CommonSeed, "save_mac_key_source", 0, 2, (set, i) -> set.DeviceUniqueSaveMacKeySources[i]));
        keys.add(new KeyInfo(252, KeyType.DeviceDrvd, "save_mac_key", 0, 2, (set, i) -> set.DeviceUniqueSaveMacKeys[i]));
        keys.add(new KeyInfo(-1, KeyType.CommonSeed, "save_mac_key_source", (set, i) -> set.DeviceUniqueSaveMacKeySources[0]));
        keys.add(new KeyInfo(253, KeyType.CommonSeed, "save_mac_sd_card_kek_source", (set, i) -> set.SeedUniqueSaveMacKekSource));
        keys.add(new KeyInfo(254, KeyType.CommonSeed, "save_mac_sd_card_key_source", (set, i) -> set.SeedUniqueSaveMacKeySource));
        keys.add(new KeyInfo(255, KeyType.DeviceDrvd, "save_mac_sd_card_key", (set, i) -> set.SeedUniqueSaveMacKey));
        keys.add(new KeyInfo(260, KeyType.DeviceRoot, "sd_seed", (set, i) -> set.SdCardEncryptionSeed));
        keys.add(new KeyInfo(261, KeyType.CommonSeed, "sd_card_kek_source", (set, i) -> set.SdCardKekSource));
        keys.add(new KeyInfo(262, KeyType.CommonSeed, "sd_card_save_key_source", (set, i) -> set.SdCardKeySources[0]));
        keys.add(new KeyInfo(263, KeyType.CommonSeed, "sd_card_nca_key_source", (set, i) -> set.SdCardKeySources[1]));
        keys.add(new KeyInfo(264, KeyType.CommonSeed, "sd_card_custom_storage_key_source", (set, i) -> set.SdCardKeySources[2]));
        keys.add(new KeyInfo(270, KeyType.CommonSeedDiff, "xci_header_key", (set, i) -> set.XciHeaderKey));
        keys.add(new KeyInfo(271, KeyType.CommonRoot, "xci_t1_titlekey_kek", 0, 0x10, (set, i) -> set.GcTitleKeyKeks[i]));
        keys.add(new KeyInfo(280, KeyType.CommonRoot, "eticket_rsa_kek", (set, i) -> set.ETicketRsaKek));
        keys.add(new KeyInfo(281, KeyType.CommonRoot, "ssl_rsa_kek", (set, i) -> set.SslRsaKek));
        keys.add(new KeyInfo(290, KeyType.CommonDrvd, "key_area_key_application", 0, 0x20, (set, i) -> set.KeyAreaKeys[i][0]));
        keys.add(new KeyInfo(300, KeyType.CommonDrvd, "key_area_key_ocean", 0, 0x20, (set, i) -> set.KeyAreaKeys[i][1]));
        keys.add(new KeyInfo(310, KeyType.CommonDrvd, "key_area_key_system", 0, 0x20, (set, i) -> set.KeyAreaKeys[i][2]));
        return keys;
    }
}
